#include <stdio.h>
#include <stdlib.h>
#include "stack_base_list.h"





/*创建节点*/

STACK_NODE *node_create(int data, STACK_NODE *next)
{
    STACK_NODE *node = malloc(sizeof(STACK_NODE));

    node->data = data;
    node->next = next;

    return node;
}

/*销毁节点*/
STACK_NODE *node_destroy(STACK_NODE *node)
{
    STACK_NODE *next = node->next;
    free(node);

    return next;

}

/*创建*/
STACK *stack_create(void)
{
    STACK *stack = malloc(sizeof(STACK));

    stack->top = NULL;

    return stack;
}

/*销毁*/
void stack_destroy(STACK *stack)
{
    stack_clear(stack);

    free(stack);
}

/*压入*/
void stack_push(STACK *stack, int data)
{
    stack->top = node_create(data, stack->top);
}

/*弹出*/
int stack_pop(STACK *stack)
{
    int data = stack->top->data;

    stack->top = node_destroy(stack->top);

    return data;
}


/*返回栈顶元素*/
int stack_top(STACK *stack)
{
    return stack->top->data;
}

/*清空*/
void stack_clear(STACK *stack)
{
    while(stack->top)
    {
        stack->top = node_destroy(stack->top);
    }
}

/*栈大小*/
int stack_size(STACK *stack)
{
    int size = 0;

    STACK_NODE *node = NULL;

    for(node=stack->top; node!=NULL; node=node->next)
    {
        size++;
    }

    return size;
}

/*判满*/
int stack_full(STACK *stack)
{
    return 0;
}

/*判空*/
int stack_empty(STACK *stack)
{
    return !stack->top;
}

